import { think } from "thinkjs";

import Base, { ServiceOption } from "../../../../service/base";
import { ITemplate } from "../types";

export class TemplateServiceClass extends Base<ITemplate> {

  constructor(option: ServiceOption) {
    super(option);
    this.restOption = {
      database: 'mongodb',
      tableName: 'template',
      privateKey: '_id',
      autoCreateUpdateTime: true,
      unAllowEdit: ['create_time', 'update_time'],
      rule: {
        title: {
          required: true
        },
        pic: {
          type: 'array'
        }
      }
    };
    this.beforeRestGet = async (option, params) => {
      // await this.checkAuth();
      return option;
    };
    this.beforeRestPut = async (option, params) => {
      // await this.checkAuth();
      return option;
    };
    this.afterRestPut = async (data, id, model) => {
      // 地图标注
      // if (data.location_lat && data.location_lng) {
      //   let res = await model.query(
      //     "UPDATE `mt_point` SET `location`=GeomFromText('POINT(" +
      //       data.location_lat +
      //       " " +
      //       data.location_lng +
      //       ")') WHERE `point_id`=" + id
      //   );
      //   console.log('[res] ', res);
      // }
    };
    this.beforeRestDelete = async (option, params) => {
      // await this.checkAuth();
      return option;
    };
  }

}

export default TemplateServiceClass;
